import AbstractField from '@/components/hhd/design/FormDesigner/field/comps/AbstractField';
import {createDefaultFieldElement} from '@/utils/FormDesignUtils';
import {createField} from '@/components/hhd/design/FormDesigner/types';
import {guid} from '@/utils';
import $ from 'jquery';

export default class Input extends AbstractField {
  getFieldComponentTitle() {
    return '文本';
  }

  getFieldComponentName() {
    return 'input';
  }

  getDefaultConfig() {
    return new Promise((resolve) => {
      let field = createField();
      field.id = guid();
      field.fieldName = '文本'
      field.label = '文本'
      field.placeholder = '请输入文本'
      resolve(field);
    });
  }

  checkField(field) {
    return super.checkField(field);
  }

  createFieldElement() {
    return new Promise((resolve) => {
      resolve(this.createDefaultFieldElement());
    })
  }

  setFieldTitle(el, fieldConfig) {
    $(el).find('span[data-role=field-title]').html(fieldConfig.label);
  }

  createDefaultFieldElement() {
    let res = createDefaultFieldElement();
    res.innerHTML = '<span data-role="field-title">文本</span>'
    return res;
  }
};
